import { GlobalTaskQueue } from "@/utils/Queue/GlobalTaskQueue";
import { GlobalTaskQueueBlocking } from "@/utils/Queue/GlobalTaskQueueBlocking";

const state = {
  taskQueue: new GlobalTaskQueue(), // 非阻塞promise队列
  taskQueueBlocking: new GlobalTaskQueueBlocking(), // 阻塞promise队列
};

const mutations = {
  ADD_TASK: (state, data) => {
    state.taskQueue.addTask(data);
  },
  ADD_TASK_BLOCKING: (state, data) => {
    state.taskQueueBlocking.addTask(data);
  },
};

const actions = {
  // 新增任务
  addTask({ commit }, data) {
    commit("ADD_TASK", data);
  },
  // 新增 阻塞
  addTaskBlocking({ commit }, data) {
    commit("ADD_TASK_BLOCKING", data);
  },
};

export default {
  namespaced: true,
  state,
  mutations,
  actions,
};
